package com.zff.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.zff.web.outsideInter.ALiYunApiService;
import com.zff.wechat.util.FileUtil;

@Controller
@RequestMapping("/aliyun")
public class WechatController {

	private static final Log LOG = LogFactory.getLog(WechatController.class);

	@Autowired
	private ALiYunApiService ALiYunApiService;
	
	@ResponseBody
	@RequestMapping(value = "/faceAge", method = RequestMethod.POST, consumes = "multipart/form-data;charset=UTF-8", produces = "application/json;charset=UTF-8")
	// requestParam要写才知道是前台的那个数组
	public String faceAge(@RequestParam("myfiles") MultipartFile[] files, HttpServletRequest request) {
		List<String> filesPaths = FileUtil.filesUpload(files, request);
		String respronse = null;
		for (String filesPath : filesPaths) {
			respronse = ALiYunApiService.faceAgeRecognition(filesPath);
		}
		LOG.info(respronse);
		String result = ALiYunApiService.faceAgeConvert(respronse);
		return result;
	}


}
